package cn.com.bsoft.cloud.dao.cloud;

import cn.com.bsoft.cloud.UseDatasourceCloud;
import cn.com.bsoft.cloud.entity.cloud.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@UseDatasourceCloud
public interface CloudMessDao {

    @Select("select routeCode,routeName  from t_route_of_administration")
    List<RouteMess> queryAllRoute();

    @Select("select routeCode,routeName from t_route_of_administration where routeCode=#{routeCode}")
    List<RouteMess> findRouteByCode(@Param("routeCode") String routeCode);

    @Select("select frequencyCode,frequencyName from t_drug_frequency")
    List<FrequencyMess> queryAllFrequency();

    @Select("select frequencyCode,frequencyName from t_drug_frequency where frequencyCode=#{frequencyCode}\n")
    List<FrequencyMess> findFrequencyByCode(@Param("frequencyCode") String frequencyCode);

    @Select("select formulationCode,formulationName from t_drug_formulation")
    List<FormulationMess> queryAllFormulation();

    @Select("select formulationCode,formulationName from t_drug_formulation where formulationCode=#{formulationCode}")
    List<FormulationMess> findFormulationByCode(@Param("formulationCode") String formulationCode);

    @Select("select doseCode,doseName from t_drug_doses")
    List<DoseMess> queryAllDoses();

    @Select("select doseCode,doseName from t_drug_doses where doseCode=#{doseCode}")
    List<DoseMess> findDoseByCode(@Param("doseCode") String doseCode);

    @Results({
            @Result(column="yydm", property="hosCode"),
            @Result(column="psdbm", property="siteCode"),
            @Result(column="psdmc", property="siteName"),
            @Result(column="psddz", property="siteAddress")
    })
    @Select("select yydm,psdbm,psdmc,psddz from t_distribution_site")
    List<SiteMess> querySite();

    @Results({
            @Result(column="yydm", property="hosCode"),
            @Result(column="psdbm", property="siteCode"),
            @Result(column="psdmc", property="siteName"),
            @Result(column="psddz", property="siteAddress")
    })
    @Select("select yydm,psdbm,psdmc,psddz from t_distribution_site where yydm=#{hosCode}")
    List<SiteMess> querySiteByHoscode(@Param("hosCode") String hosCode);

    @Results({
            @Result(column="yydm", property="hosCode"),
            @Result(column="psdbm", property="siteCode"),
            @Result(column="psdmc", property="siteName"),
            @Result(column="psddz", property="siteAddress")
    })
    @Select("select yydm,psdbm,psdmc,psddz from t_distribution_site where yydm=#{hosCode} and psdbm=#{siteCode}")
    List<SiteMess> querySiteByCode(@Param("hosCode") String hosCode, @Param("siteCode") String siteCode);
}
